<?php

class CVirtual extends Zend_Db_Table{
	
	protected $_name;
	
	protected $_primary;
	
	public function _setup(){
		
		$this->_name=R_PRE."virtuals";
		
		$this->_primary="id";
		
		parent::_setup();
		
	}
	
	public function getDetail($name){
		
		$db=$this->getAdapter();
		
		$select=$db->select();
		
		$select->from($this->_name,'value');
		
		$select->where(' name = ? ',$name);
		
		return $db->fetchOne($select);
		
	}
	
	
	public function editVirtual($name,$data){
		
		$db=$this->getAdapter();
		
		$where = $db->quoteInto('name = ?', $name);

		$rows_affected=$db->update($this->_name,$data,$where);
		
		if($rows_affected!=1){
			
			return false;
			
		}else{
			
			return true;
			
		}
		
	}
	
	public function getAllVirtual(){
		
		$db=$this->getAdapter();
		
		$select=$db->select();
		
		$select->from($this->_name,'*');
		
		return $db->fetchAll($select);
		
	}
	
	public function addVirtual($virtual,$where){
		
		$db=$this->getAdapter();
		
		return $db->query('UPDATE '.R_PRE.'members SET virtual=round(virtual+'.$virtual.',2) '.$where);
		
	}
	
	public function subVirtual($virtual,$where){
		
		$db=$this->getAdapter();
		
		return $db->query('UPDATE '.R_PRE.'members SET virtual=round(virtual-'.$virtual.',2) '.$where);
		
	}

	
}